package com.shuoyue.ycgk.ui.mine.vip;

import com.shuoyue.ycgk.base.BaseModel;
import com.shuoyue.ycgk.base.BasePresenter;
import com.shuoyue.ycgk.base.BaseResult;
import com.shuoyue.ycgk.base.BaseView;
import com.shuoyue.ycgk.entity.Type;
import com.shuoyue.ycgk.entity.VipPrice;
import com.shuoyue.ycgk.entity.VipType;
import com.shuoyue.ycgk.net.RetrofitClient;
import com.shuoyue.ycgk.net.base.ApiSubscriber;
import com.shuoyue.ycgk.net.gsondefaultadapter.Optional;

import java.util.List;

import io.reactivex.Observable;

public interface VipContract {
    interface View extends BaseView {
        void setBaseType(List<VipType> baseTypes);

        void setPriceList(List<VipPrice> vipPrices);

    }

    class Presenter extends BasePresenter<View> {
        Model model = new Model();

        public void getVipModel() {
            apply(model.getBaseType())
                    .subscribe(new ApiSubscriber<Optional<List<VipType>>>(mView, this) {
                        @Override
                        public void onNext(Optional<List<VipType>> listOptional) {
                            super.onNext(listOptional);
                            mView.setBaseType(listOptional.getIncludeNull());
                        }
                    });
        }

        public void getVipPrice(int subjectTypeId) {
            apply(model.getVipPrice(subjectTypeId))
                    .subscribe(new ApiSubscriber<Optional<List<VipPrice>>>(mView, this) {
                        @Override
                        public void onNext(Optional<List<VipPrice>> listOptional) {
                            super.onNext(listOptional);
                            mView.setPriceList(listOptional.getIncludeNull());
                        }
                    });
        }
    }

    class Model extends BaseModel {
        Observable<BaseResult<List<VipType>>> getBaseType() {
            return RetrofitClient.getInstance().getApi().getVipTypes();
        }

        Observable<BaseResult<List<VipPrice>>> getVipPrice(int subjectTypeId) {
            return RetrofitClient.getInstance().getApi().getVipPrice(subjectTypeId);
        }
    }
}
